namespace DotNetNuke.Services.Search
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Runtime.CompilerServices;

    /// -----------------------------------------------------------------------------
    /// Namespace:  DotNetNuke.Services.Search
    /// Project:    DotNetNuke
    /// Class:      SearchItemInfoCollection
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// Represents a collection of <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> objects.
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// [cnurse]	11/15/2004	documented
    /// </history>
    /// -----------------------------------------------------------------------------
    public class SearchItemInfoCollection : CollectionBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> class.
        /// </summary>
        public SearchItemInfoCollection()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> class containing the elements of the specified source collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> with which to initialize the collection.</param>
        public SearchItemInfoCollection(SearchItemInfoCollection value)
        {
            this.AddRange(value);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> class containing the specified array of <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> objects.
        /// </summary>
        /// <param name="value">An array of <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> objects with which to initialize the collection. </param>
        public SearchItemInfoCollection(SearchItemInfo[] value)
        {
            this.AddRange(value);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollectionSearchItemInfoCollection</see> class containing the specified array of <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> objects.
        /// </summary>
        /// <param name="value">An arraylist of <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> objects with which to initialize the collection. </param>
        public SearchItemInfoCollection(ArrayList value)
        {
            this.AddRange(value);
        }

        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> to the end of the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> to add to the collection.</param>
        public int Add(SearchItemInfo value)
        {
            return this.List.Add(value);
        }

        /// <summary>
        /// Adds the contents of another <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> to the end of the collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> containing the objects to add to the collection. </param>
        public void AddRange(SearchItemInfoCollection value)
        {
            int refIntHelperL0 = value.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this.Add((SearchItemInfo) value.List[i]);
            }
        }

        /// <summary>
        /// Copies the elements of the specified <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> array to the end of the collection.
        /// </summary>
        /// <param name="value">An array of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> containing the objects to add to the collection.</param>
        public void AddRange(SearchItemInfo[] value)
        {
            int refIntHelperL0 = value.Length - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this.Add(value[i]);
            }
        }

        /// <summary>
        /// Copies the elements of the specified arraylist to the end of the collection.
        /// </summary>
        /// <param name="value">An arraylist of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> containing the objects to add to the collection.</param>
        public void AddRange(ArrayList value)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = value.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    object obj = RuntimeHelpers.GetObjectValue(refObjectHelperL0.Current);
                    if (obj is SearchItemInfo)
                    {
                        this.Add((SearchItemInfo) obj);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        /// <summary>
        /// Gets a value indicating whether the collection contains the specified <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see>.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> to search for in the collection.</param>
        /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
        public bool Contains(SearchItemInfo value)
        {
            return this.List.Contains(value);
        }

        /// <summary>
        /// Copies the collection objects to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param>
        /// <param name="index">The index of the array at which to begin inserting.</param>
        public void CopyTo(SearchItemInfo[] array, int index)
        {
            this.List.CopyTo(array, index);
        }

        /// <summary>
        /// Gets the index in the collection of the specified <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see>, if it exists in the collection.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> to locate in the collection.</param>
        /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
        public int IndexOf(SearchItemInfo value)
        {
            return this.List.IndexOf(value);
        }

        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> to the collection at the designated index.
        /// </summary>
        /// <param name="index">An <see cref="T:System.Int32">Integer</see> to indicate the location to add the object to the collection.</param>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> to add to the collection.</param>
        public void Insert(int index, SearchItemInfo value)
        {
            this.List.Insert(index, value);
        }

        public SearchItemInfoCollection ModuleItems(int ModuleId)
        {
            IEnumerator refObjectHelperL0=null;
            SearchItemInfoCollection retValue = new SearchItemInfoCollection();
            try
            {
                refObjectHelperL0 = this.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    SearchItemInfo info = (SearchItemInfo) refObjectHelperL0.Current;
                    if (info.ModuleId == ModuleId)
                    {
                        retValue.Add(info);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            return retValue;
        }

        /// <summary>
        /// Remove the specified object of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> from the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Search.SearchItemInfo">SearchItemInfo</see> to remove to the collection.</param>
        public void Remove(SearchItemInfo value)
        {
            this.List.Remove(value);
        }

        /// <summary>
        /// Creates a one-dimensional <see cref="T:System.Array">Array</see> instance containing the collection items.
        /// </summary>
        /// <returns>Array of type SearchItemInfo</returns>
        public SearchItemInfo[] ToArray()
        {
            SearchItemInfo[] arr={};
            arr = (SearchItemInfo[]) Utils.CopyArray((Array) arr, new SearchItemInfo[(this.Count - 1) + 1]);
            this.CopyTo(arr, 0);
            return arr;
        }

        /// <summary>
        /// Gets the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> at the specified index in the collection.
        /// <para>
        /// In VB.Net, this property is the indexer for the <see cref="T:DotNetNuke.Services.Search.SearchItemInfoCollection">SearchItemInfoCollection</see> class.
        /// </para>
        /// </summary>
        public SearchItemInfo this[int index]
        {
            get
            {
                return (SearchItemInfo) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }
    }
}

